//
// Created by tcj on 2022/3/22.
//

#include "sylar/address.h"
#include "sylar/log.h"


sylar::Logger::ptr  g_logger = SYLAR_LOG_ROOT();

//void test(){
//    std::vector<sylar::Adress::ptr> addrs;
//    bool v = sylar::Adress::Lookup(addrs,"www.baidu.com");
//
//    if(!v){
//        SYLAR_LOG_ERROR(g_logger)<<"lookup fail";
//        return;
//    }
//    for(size_t i=0;i<addrs.size();++i){
//        SYLAR_LOG_INFO(g_logger)<<i<<" - "<<addrs[i]->toString();
//    }
//
//}
void test(){
    std::vector<sylar::Adress::ptr> addrs;
    bool v = sylar::Adress::Lookup(addrs,"www.baidu.com",AF_INET);
    if(!v){
        SYLAR_LOG_ERROR(g_logger)<<"lookup fail";
        return;
    }
    for(size_t i=0;i<addrs.size();++i){
        SYLAR_LOG_INFO(g_logger)<<i<<" - "<<addrs[i]->toString();
    }

}


void test_iface(){
    std::multimap<std::string,std::pair<sylar::Adress::ptr,uint32_t>> results;
    bool v = sylar::Adress::GetInterfaceAddresses(results);

    if(!v){
        SYLAR_LOG_ERROR(g_logger)<<"getInterfaceaddress fail";
        return ;
    }
    for(auto& i:results){
        SYLAR_LOG_INFO(g_logger)<<i.first<<" - "<<i.second.first->toString()<<" - "<<
            i.second.second;
    }
}

void test_ipv4(){
    sylar::IPv4Adress::ptr addr = sylar::IPv4Adress::Create("www.baidu.com");
//    auto addr = sylar::IPv4Adress::Create("127.168.3.1");

    if(addr){
        SYLAR_LOG_INFO(g_logger)<<addr->toString();
    }
}
int main(int argc,char **argv){
//    test_ipv4();
    test();
//    test_iface();
//    test_ipv4();
    return 0;
}